import Editor from "../../editor";
import {debounce} from "../../utils/debounce";

export function undoRedo(editor: Editor) {
    const originApply = editor.apply.bind(editor)
    let undoArr: { apply: () => void; reverse: () => void; }[] = []
    let redoArr = []
    //这一步是将原子操作放入undoArr中
    editor.apply = function (operation: any) {
        undoArr.push({
            apply: () => editor.apply(operation),
            reverse: () => editor.inverse(operation)
        })
        console.log(undoArr)
        originApply(operation)
    }

    editor.undo = function () {
        if (undoArr.length === 0) return

    }

    return editor
}